package com.onest;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class JdkProxy implements InvocationHandler {
    private Object target;
    public Object createProxy(Object target){
        this.target=target;
        return Proxy.newProxyInstance(JdkProxy.class.getClassLoader(),target.getClass().getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        MyAspect myAspect=new MyAspect();
        myAspect.checkPermissions();
        Object obj=method.invoke(target,args);
        myAspect.log();
        return obj;
    }
}
